#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import List, Dict
from .base import FilterRule

class TypeBaseFilter(FilterRule):
    """基于修改类型的过滤规则"""
    
    def __init__(self, allowed_types: List[str] = None):
        """
        初始化修改类型过滤器
        
        Args:
            allowed_types: 允许的修改类型列表，默认为['modify']
        """
        if allowed_types is None:
            allowed_types = ['modify']
        self.allowed_types = allowed_types
    
    def should_filter(self, add_content: str, remove_content: str, hunk_changes: List[Dict]) -> bool:
        """判断是否应该过滤"""
        change_type = self._determine_change_type(add_content, remove_content)
        return change_type not in self.allowed_types
    
    def get_filter_reason(self) -> str:
        """获取过滤原因"""
        return f"修改类型不在允许列表中: {self.allowed_types}"
    
    def _determine_change_type(self, add_content: str, remove_content: str) -> str:
        """确定修改类型"""
        if add_content and remove_content:
            return 'modify'
        elif add_content and not remove_content:
            return 'add'
        elif remove_content and not add_content:
            return 'delete'
        else:
            return 'unknown' 